package fr.agriparcelle.server.dao;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;

import fr.agriparcelle.shared.User;

/**
 * 
 * @author Parant
 * 
 */
public class CredentialsDaoImpl implements CredentialsDao {

	private PersistenceManagerFactory persistenceManagerFactory;

	@Override
	public void saveUser(User user) {
		Query query = null;
		PersistenceManager pm = this.persistenceManagerFactory.getPersistenceManager();
		pm.makePersistent(user);

		// test des query JDO
		query = pm.newQuery(User.class);
		query.setFilter("lastName == lastNameParam");
		query.declareParameters("String lastNameParam");

		@SuppressWarnings("unchecked")
		List<User> results = (List<User>) query.execute("PARANT");
		if (!results.isEmpty()) {
			// do stuff
		}
	}

	public PersistenceManagerFactory getPersistenceManagerFactory() {
		return persistenceManagerFactory;
	}

	public void setPersistenceManagerFactory(PersistenceManagerFactory pmf) {
		this.persistenceManagerFactory = pmf;
	}
}
